package xyz.weizhi.tanhua.appserver.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import xyz.weizhi.commons.utils.JwtUtils;
import xyz.weizhi.tanhua.appserver.service.UserService;
import xyz.weizhi.tanhua.model.vo.UserInfoVo;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @Author milian
 * @Date 2021/10/21 0021 14:24
 */
@RestController
@RequestMapping("/user")
public class LoginController {
    @Autowired
    private UserService usesService;
    /** 
     * @Author milian
     * @Description //TODO 发送验证码
     * @Date 19:15 2021/10/21 0021
     * @Param [map]
     * @return org.springframework.http.ResponseEntity
     **/
    @PostMapping("/login")
    public ResponseEntity Login(@RequestBody Map map){
        String phone = (String) map.get("phone");
        usesService.sendMsg(phone);
        return ResponseEntity.ok(null);
    }
    /** 
     * @Author milian
     * @Description //TODO 登录验证
     * @Date 19:14 2021/10/21 0021
     * @Param [map]
     * @return org.springframework.http.ResponseEntity
     **/
    @PostMapping("/loginVerification")
    public ResponseEntity LoginVerification(@RequestBody Map map){
        // 获取用户输入的电话和验证码
        String phone = (String) map.get("phone");
        String verificationCode = (String) map.get("verificationCode");
        Map retMap = usesService.loginVerification(phone, verificationCode);
        return ResponseEntity.ok(retMap);
    }
}
